package com.bbs.web.controller;

import com.bbs.entity.Result;
import com.bbs.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/web/getReport")
public class GetReportController {


    @Autowired
    private ReportService reportService;

    @PostMapping("/add")
    public Result add(@RequestBody Map reportMap, HttpSession session){
        String username = (String) session.getAttribute("username");
//        username="a";
        if (username==null){
            return new Result(1,"请登录后再举报");
        }
        String reportContent = (String) reportMap.get("reportContent");
        Integer articleId = (Integer) reportMap.get("articleId");
        if (reportContent==null){
            return new Result(1,"举报内容不能为空");
        }
        return reportService.add(reportContent,articleId,username);

    }
}
